<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生项目管理')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <input id="teacherId" name="teacherId"  th:value="*{teacherId}" hidden="true">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>时间：</label>
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" class="col-sm-3 control-label" id="scheduleTime" placeholder="yyyy-MM-dd">
                                <label style="width: 25px"></label>
                                <label>学生姓名：</label>
                                <input id="childName" type="text" class="col-sm-3 control-label" name="childName" />
                                <label style="width: 25px"></label>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            </div>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    // 字典
    var prefix = ctx + "education/schedule";
    var reportPrefix = "education/trainingReport";
    $(function(){
        layui.use('laydate', function(){
            layui.laydate.render({
                elem: '#scheduleTime',
                value: new Date(),
                format: 'yyyy-MM',
                type: 'month'
            });
        })
    });

    $(function () {
        var options = {
            url: prefix + "/listReportChildren",
            queryParams: queryParams,
            modalName: "数据",
            columns: [
                {
                    field: 'childName',
                    title: '学员姓名',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="downLoadReport(\'' + row.childId + '\')"><i class="fa fa-edit"></i>下载</a>');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="checkReport(\'' + row.childId + '\')" style="margin-left: 15px"><i class="fa fa-edit"></i>查看</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function edit(arr) {
        var data = arr.split(",");
        var scheduleTime = $('#scheduleTime').val();
        $.modal.openTab("训练项目编辑", prefix + "/edit/"+data[0]+"/"+data[1]+"/"+scheduleTime);
    }

    function checkReport(childId) {
        if(!childId){
            $.modal.alertWarning("学生ID为空");
            return;
        }
        var scheduleTime = $('#scheduleTime').val();
        $.modal.openTab("查看训练报告", reportPrefix + "/checkReport/"+childId+"/"+scheduleTime);
    }

    function queryParams(params) {
        var search = $.table.queryParams(params);
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            var centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
            search.centerId = centerId;
        }
        var scheduleTime = $('#scheduleTime').val();
        var teacherId = $('#teacherId').val();
        search.scheduleTime =scheduleTime;
        search.teacherId =teacherId;
        return search;
    }
    function downLoadReport(childId) {
        if(!childId){
            $.modal.alertWarning("学生ID为空");
            return;
        }
        var scheduleTime = $('#scheduleTime').val();
        var formData = new FormData();
        formData.set("trainingProgramNumber",scheduleTime);
        formData.set("childId", childId);
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            var centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
            formData.set("centerId", centerId);
        }
        $.ajax({
            url: prefix+"/downloadTrainingReport",
            type: "post",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success: function (result) {
                if (result.code == '0') {
                    window.open(result.msg)
                } else {
                    $.modal.alertWarning(result.msg);

                }
            }
        })
    }

</script>
</body>

</html>